<template>
	<view>
		<!-- <button @click="get">获取位置</button> -->
		<view v-show="active !== 'room'" style="margin-left: 223rpx;margin-top: 20rpx;">
			<uploader @input="onChange" :max="1" />
		</view>
		<uni-forms-item required label="检查点类型:">
			<view :class="label == '请选择检查点类型' ? 'color':''" class="tap" @click="handleTap('picker')">{{label}}</view>
			<lb-picker ref="picker" @click="handleTap('picker')" v-model="value" mode="selector" :list="pointTypeList" :dataset="{ name: 'label' }"
			 @confirm="handleConfirm" @cancel="handleCancel">
			</lb-picker>
		</uni-forms-item>
		<company-info @submit="createCheckPoint" v-if="active == 'company'"></company-info>
		<restaurant-info @submit="createCheckPoint" v-else-if="active == 'restaurant'"></restaurant-info>
		<clinic-info @submit="createCheckPoint" v-else-if="active == 'clinic'"></clinic-info>
		<village-info @submit="createCheckPoint" v-else-if="active == 'residential'"></village-info>
		<shop-info @submit="createCheckPoint" v-else-if="active == 'shop'"></shop-info>
		<public-info @submit="createCheckPoint" v-else-if="active == 'watercourse'"></public-info>
		<room-info @submit="addRoom" v-else></room-info>
		<!-- <van-tabs @change="changeTab" color="#42ADFF" animated :lazy-render="false" :active="active">
			<van-tab :title-style="active == 0 ? 'color: #42ADFF': ''" title="企业">
				<company-info></company-info>
			</van-tab>
			<van-tab :title-style="active == 1 ? 'color: #42ADFF': ''" title="小餐饮店">
				<restaurant-info></restaurant-info>
			</van-tab>
			<van-tab :title-style="active == 2 ? 'color: #42ADFF': ''" title="个体诊所">
				<clinic-info></clinic-info>
			</van-tab>
			<van-tab :title-style="active == 3 ? 'color: #42ADFF': ''" title="住宅小区">
				<village-info></village-info>
			</van-tab>
			<van-tab :title-style="active == 4 ? 'color: #42ADFF': ''" title="出租房屋">
				<lodge-info></lodge-info>
			</van-tab>
		</van-tabs> -->
	</view>
</template>

<script>
	import CompanyInfo from '../components/companyInfo.vue'
	import VillageInfo from '../components/villageInfo.vue'
	import ClinicInfo from '../components/clinicInfo.vue'
	import ShopInfo from '../components/shopInfo.vue'
	import PublicInfo from '../components/publicInfo.vue'
	import RestaurantInfo from '../components/restaurantInfo.vue'
	import RoomInfo from '../components/roomInfo.vue'
	import uploader from '../myComponents/image-uploader.vue'
	import LbPicker from '../components/lb-picker/index.vue'
	export default {
		components: {
			RoomInfo,
			CompanyInfo,
			VillageInfo,
			ClinicInfo,
			ShopInfo,
			RestaurantInfo,
			uploader,
			LbPicker,
			PublicInfo
		},
		data() {
			return {
				typeObj: this.$type.typeObj,
				type: '',
				url: '',
				label: '请选择检查点类型',
				active: 'company',
				value: '',
				params: {
					照片上传: null
				},
				pointTypeList: this.$type.pointTypeList
			}
		},
		onLoad(options) {
			console.log(typeof options.type)
			if(options.type !== undefined) {
				this.type = options.type
				this.label = this.$type.checkPointType[options.type]
				this.active = options.type
				if(options.type == 8) {
					this.label = '房屋'
					this.active = 'room'
				}
			}
			if(options.url) {
				this.url = options.url
				console.log(options.url)
			}
		},
		methods: {
			addRoom(params) {
				uni.showLoading({
					mask: true
				})
				this.$http.post('gridSystem/room/create', params).then(res => {
					console.log(res)
					if(res.code === 10000){
						if(this.type) {
							this.url = this.url + '?type=' + this.typeObj[this.type]
						}
						// console.log(this.url)
						uni.reLaunch({
							url: this.url
						})
					}
				})
			},
			createCheckPoint(params) {
				uni.showLoading({
					mask: true
				})
				if (params.公司) {
					params.公司.照片上传 = this.params.照片上传
				}
				if (params.小餐饮店) {
					params.小餐饮店.照片上传 = this.params.照片上传
				}
				if (params.个体诊所) {
					params.个体诊所.照片上传 = this.params.照片上传
				}
				if (params.高层住宅小区) {
					params.高层住宅小区.照片上传 = this.params.照片上传
				}
				if (params.商铺) {
					params.商铺.照片上传 = this.params.照片上传
				}
				if (params.公共区域) {
					params.公共区域.照片上传 = this.params.照片上传
				}
				// params.小餐饮店.照片上传 = params.小餐饮店.照片上传 && this.params.照片上传
				// params.高层住宅小区.照片上传 = params.高层住宅小区.照片上传 && this.params.照片上传
				// params.个体诊所.照片上传 = params.个体诊所.照片上传 && this.params.照片上传
				this.$http.post('gridSystem/checkPoint/add', params).then(res => {
					console.log(res)
					if (res.code === 10000) {
						if(this.type) {
							this.url = this.url + '?type=' + this.typeObj[this.type]
						}
						console.log(this.url)
						uni.reLaunch({
							url: this.url
						})
						// uni.showToast({
						// 	title: '提交成功'
						// })
					}
				})
			},
			onChange(e) {
				this.params.照片上传 = e
			},
			handleTap(name) {
				this.$refs[name].show()
			},
			handleConfirm(e) {
				if (e) {
					console.log(e)
					const name = e.dataset.name
					const label = e.item.label
					this.active = e.item.id
					console.log()
					// this.params4.education = e.item.id
					if (name && label) {
						this[name] = label
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.color {
		color: #808080;
	}
</style>
